local ScrollView = class("ScrollView");
function ScrollView:ctor(args)
    self.sv = args.sv;
    self.dis = args.dis or 0;
    self.content = display.newLayer();
    self.count = 0;
    self.sv:setTouchEnabled(true);
    self:setBounceable(true);
    self.sv:onScroll(handler(self,self.onScroll));
end


function ScrollView:setBounceable(b)
    self.sv:setBounceable(b);
end

function ScrollView:addContent(item)
    self.count = self.count + 1;
    local size = item:getContentSize();
    --item:ignoreAnchorPointForPosition(false);
    --item:setAnchorPoint(cc.p(0.5,0.5));
    local width = (self.count - 1) * self.dis + (self.count) * size.width;
    self.content:setContentSize(cc.size(width,size.height));
    local w = (self.count - 1) * size.width + (self.count - 1) * self.dis;
    item:setPosition(cc.p(w,0));
    self.content:addChild(item);
end

function ScrollView:addScrollNode()
    local rect = self.sv:getViewRect();
    self.content:setPosition(cc.p(rect.x,rect.y));
    self.sv:addScrollNode(self.content);
end

function ScrollView:setOnScrollCbk(cbk)
    self.onScrollCbk = cbk or nil;
end

function ScrollView:onScroll(event)
    if self.onScrollCbk then
        self.onScrollCbk(event);
    end
end

return ScrollView;

--endregion
